#!/usr/bin/env python
"""Ssh object to handle sending bash commands via ssh.  Assumes that ssh keys
and such are already configured. A ping command for RyCE.
"""
__plugin_name__ = 'ssh'
#-IMPORTS----------------------------------------------------------------------
import os
import cmdobj
import cmdline
#-CONSTANTS--------------------------------------------------------------------
DEFAULT_USER = 'root'
#-CLASSES----------------------------------------------------------------------
class ssh(cmdobj.CmdObject):
    """Command plugin that executes a ping.
    """
    def __init__(self, p_params):
        t_args = []
        self.__ip = p_params[cmdobj.IP]
        t_args.append(self.__ip)
        t_args.append('-l')
        if hasattr(cmdline.options, 'user'):
            t_args.append(cmdline.options.user)
        else:
            t_args.append(DEFAULT_USER)
        t_args.extend(p_params[cmdobj.ARGS])
        if os.name == 'posix':
            cmdobj.CmdObject.__init__(self,
                                      p_os   = 'posix',
                                      p_cmd  = 'ssh',
                                      p_args = t_args,
                                      p_name = __plugin_name__)
        elif (os.name == 'nt') or (os.name == 'dos'):
            cmdobj.CmdObject.__init__(self,
                                      p_os   = 'nt',
                                      p_cmd  = 'ssh.exe',
                                      p_args = t_args,
                                      p_name = __plugin_name__)
